package cruncher;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class LocalSearchFactors {
	public int INITIAL_SOLUTIONS_NUMBER;// = 3;
	public int ITERATION_TIME;// = 3*60;
	public double FIXING_FRACTION;// = 0.8;
	public double FIXING_FRACTION_DELTA;// = 0.05; //how much to decrease the fraction
	public int LOCAL_MINIMUM_THRESHOLD;// = 3;
	public double MIP_RELATIVE_GAP_THRESHOLD;// = 0.1;
	
	protected static final String PARAMETERS_FILENAME = "NaiveCruncher.properties.txt";
	
	public LocalSearchFactors() {
		// create and load default properties
		Properties props = new Properties();
		FileInputStream in;
		try {
			in = new FileInputStream(PARAMETERS_FILENAME);
			props.load(in);
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		try	{
		INITIAL_SOLUTIONS_NUMBER = Integer.parseInt(props.getProperty("INITIAL_SOLUTIONS_NUMBER"));
		ITERATION_TIME = Integer.parseInt(props.getProperty("ITERATION_TIME"));
		FIXING_FRACTION = Double.parseDouble(props.getProperty("FIXING_FRACTION"));
		FIXING_FRACTION_DELTA = Double.parseDouble(props.getProperty("FIXING_FRACTION_DELTA"));
		LOCAL_MINIMUM_THRESHOLD = Integer.parseInt(props.getProperty("LOCAL_MINIMUM_THRESHOLD"));
		MIP_RELATIVE_GAP_THRESHOLD = Double.parseDouble(props.getProperty("MIP_RELATIVE_GAP_THRESHOLD"));
		} catch (Exception e)
		{
			e.printStackTrace();
			System.err.println("Couldn't parse parameters file " + PARAMETERS_FILENAME);
			System.exit(1);
		}
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append(String.format("Number of initial solutions: %d \n",INITIAL_SOLUTIONS_NUMBER));
		builder.append(String.format("Iteration time: %d seconds\n",ITERATION_TIME));
		builder.append(String.format("Fixing fraction: %4.2f \n",FIXING_FRACTION));
		builder.append(String.format("Fixing fraction delta: %4.2f \n",FIXING_FRACTION_DELTA));
		builder.append(String.format("MIP relative gap for polishing: %4.2f \n",MIP_RELATIVE_GAP_THRESHOLD));
		return builder.toString();
	}
	
}
